|
|
|
|
|
|
|
when the error occurred. In addition, you will learn how a Visual Basic application processes an error. |
|
|
|
|
|
|
|
|
Before we start discussing error handling, I would like to make a blanket statement: |
|
|
|
 |
|
|
|
|
Errors will occur, no matter how good you are! So get over it. |
|
|
|
|
|
|
|
|
This might sound a bit pretentious, but many programmers think that they cannot make a mistake. And as always, that is their first mistake. You can only create good error-handling routines if you accept the fact that you can make a mistake when designing an application. |
|
|
|
|
|
|
|
|
Unfortunately, no matter how good your testing is, there will always be errors that you did not think of or expect in your application. Because the coding of an error routine isn't easy, fun, or exciting, many programmers fall a little short in the anticipation and prevention of any application errors. When this happens, Visual Basic often takes control and abnormally exits your application. This can result in lost data if the error is severe enough. |
|
|
|
|
|
|
|
|
Once Visual Basic is involved in handling the error, your application has already been stopped. There is no way at that point for you to undo the damage and allow the application to continue processing. Even more dangerously, if the error doesn't stop your application, it might continue executing with unpredictable results. Like everything else in programming, error handling requires good design skills to create good error-handling routines. In a well-designed application, errors are handled by the application and trapped before Visual Basic ever sees it. |
|
|
|
|
|
|
|
|
Before handling any errors, you should understand the types of errors that can occur. The term error actually covers a multitude of programming problems that pop up during the design, creation, and testing phases of application development. There are four distinct types of errors: |
|
|
|
|
|